package com.chuhe.starry.service.adapter;

import com.chuhe.common.domain.dto.TokenUserInfoDto;
import com.chuhe.common.domain.entity.GroupInfo;
import com.chuhe.common.domain.entity.UserContact;
import com.chuhe.common.domain.enums.UserContactStatusEnum;
import com.chuhe.common.domain.enums.UserContactTypeEnum;
import com.chuhe.common.domain.vo.resp.LoadGroupResp;
import com.chuhe.common.domain.vo.resp.SaveGroupReq;
import com.chuhe.common.utils.StringTools;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @Author: 楚河
 * @Date: 2025年05月13日18:19
 */
public class SaveGroupAdapter {
    /**
     * 组装群组信息
     * @Author: 楚河
     * @Date: 2025-05-13 18:20
     */
    public static GroupInfo buildGroup(SaveGroupReq req, TokenUserInfoDto tokenUserInfo) {
        Date curDate = new Date();
        GroupInfo group = new GroupInfo();
        group.setGroupId(req.getGroupId());
        group.setGroupOwnerId(tokenUserInfo.getUserId());
        group.setGroupName(req.getGroupName());
        group.setGroupNotice(req.getGroupNotice());
        group.setJoinType(req.getJoinType());
        group.setCreateTime(curDate);
        return group;
    }

    /**
     * 组装联系人
     * @Author: 楚河
     * @Date: 2025-05-13 23:01
     */
    public static UserContact buildGroupToUserContact(GroupInfo groupInfo) {
        Date date = new Date();
        UserContact contact = new UserContact();
        contact.setStatus(UserContactStatusEnum.FRIEND.getStatus());
        contact.setContactType(UserContactTypeEnum.GROUP.getType());
        contact.setContactId(groupInfo.getGroupId());
        contact.setUserId(groupInfo.getGroupOwnerId());
        contact.setCreateTime(date);
        contact.setLastUpdateTime(LocalDateTime.now());
        return contact;
    }
    /**
     * 组装群组详情
     * @Author: 楚河
     * @Date: 2025-05-14 19:50
     */
    public static LoadGroupResp buildGroupDetail(GroupInfo groupInfo,Integer count) {
        LoadGroupResp loadGroupResp = new LoadGroupResp();
        BeanUtils.copyProperties(groupInfo, loadGroupResp);
        loadGroupResp.setMemberCount(count);
        return loadGroupResp;
    }
}
